package org.aftputil;

import java.awt.Color;
import java.awt.Component;

import javax.swing.*;

public class AftpListCellRenderer extends JLabel implements ListCellRenderer
{
	 private static final Color HIGHLIGHT_COLOR = new Color(20, 50, 128);
	public AftpListCellRenderer() 
	{
	  this.setOpaque(true);
	  this.setIconTextGap(10);
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) 
	{
		int space = 20;
		AftpFileItem obj = (AftpFileItem)value;
		if(obj == null ) return null;
			
		this.setIcon(obj.getImage());
		String text = obj.getName()+"  ";
		if(text.length() < space)
		{
			int len = space-text.length();
			String tmp = "";
			for(int i = 0;i < len; i++)
				tmp+=" ";
			text+=tmp;
		}
		
		//text+=obj.getSize()+"    "+obj.getLastModified().toLocaleString();
		this.setText(text);
		
		 if (isSelected) 
		 {
		      setBackground(HIGHLIGHT_COLOR);
		      setForeground(Color.WHITE);
		    }
		 else
		    {
		      setBackground(Color.white);
		      setForeground(Color.black);
		    }
		return this;
	}

}
